package com.oromwin.repos.server.response;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;

import com.oromwin.repos.common.Logger;
import com.oromwin.repos.common.ReposException;
import com.oromwin.repos.common.helper.IOHelper;
import com.oromwin.repos.data.VolumeTable;
import com.oromwin.repos.server.response.volume.ListVolumeResponse;

public class ListRepositoryResponse extends NormalResponse {
    private Log log = Logger.getLog(ListVolumeResponse.class);
    private int size = 0;
    private List volumeTableList = null;

    public ListRepositoryResponse() {
        volumeTableList = new ArrayList();
    }

    public void receive(DataInputStream dis) throws ReposException {
        try {
            Result = dis.readBoolean();
            Description = IOHelper.readUTF8(dis);
            size = dis.readInt();
            for (int i = 0; i < size; i++) {
                String volumeId = IOHelper.readUTF8(dis);
                String volumeName = IOHelper.readUTF8(dis);
                Boolean volumeStatus = new Boolean(dis.readBoolean());
                String volumeCreateDate = IOHelper.readUTF8(dis);
                String volumeUpdateDate = IOHelper.readUTF8(dis);
                VolumeTable volumeTable = new VolumeTable(volumeId, volumeName, volumeStatus, volumeCreateDate, volumeUpdateDate);
                volumeTableList.add(volumeTable);
            }
        } catch (IOException e) {
            throw ReposException.create(log, e);
        }
    }

    public List getVolumeTableList() {
        return volumeTableList;
    }
}
